const mongoose = require('mongoose').set('debug', true);
const options = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
};

const dburl = 'mongodb://127.0.0.1:27017/vblog';

module.exports = {
  connect: () => {
    // 链接MongoDB数据库
    mongoose.connect(dburl, options);
    let db = mongoose.connection;
    db.on('error', console.error.bind(console, '连接错误:'));
    db.on("connected", function () {
      console.log("MongoDB connected success")
    });
    db.on("disconnected", function () {
      console.log("MongoDB connected disconnected")
    });
    db.once('open', () => {
      console.log('mongodb opened suucess');
    });
  }
};
